package com.douyang.listen;


import com.douyang.config.RabbitMQConfig;
import com.douyang.dto.PayOrderDTO;
import com.douyang.model.MqMessage;
import com.douyang.service.MqMessageService;
import com.douyang.service.PayOrderBaseService;
import com.douyang.service.PayOrderDetailService;
import com.douyang.vo.PayOrderVO;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MqListen {

    @Autowired
    private PayOrderBaseService payOrderBaseService;

    @Autowired
    private PayOrderDetailService payOrderDetailService;

    @Autowired
    MqMessageService mqMessageService;

    @RabbitListener(queues = RabbitMQConfig.MAIN_QUEUE)
    public void createPayOrder(PayOrderDTO payOrderDTO) {
        payOrderBaseService.createPayOrder(payOrderDTO);
    }

    @RabbitListener(queues = RabbitMQConfig.DLX_QUEUE)
    public void saveFailToDB(PayOrderDTO payOrderDTO) {
        mqMessageService.saveFailToDB(payOrderDTO);
    }



    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name="direct.queue2"),
            exchange = @Exchange(name="trade.direct2",type = ExchangeTypes.DIRECT,delayed = "true"),
            key ={"checkOrder"}
    ))
    public void checkOrder(Long orderId){
        payOrderDetailService.checkOrder(orderId);
    }



}
